home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / scripttemplate_gamelogic.py < prev    next >
Text File  |  2009-08-31  |  3KB  |  98 lines

  1. #!BPY
  2. """
  3. Name: 'GameLogic Example'
  4. Blender: 249
  5. Group: 'ScriptTemplate'
  6. Tooltip: 'Script template with examples of how to use game logic'
  7. """
  8.  
  9. from Blender import Window
  10. import bpy
  11.  
  12. script_data = \
  13. '''
  14. # This script must be assigned to a python controller
  15. # where it can access the object that owns it and the sensors/actuators that it connects to.
  16.  
  17. # GameLogic has been added to the global namespace no need to import
  18.  
  19. # for keyboard event comparison
  20. # import GameKeys 
  21.  
  22. # support for Vector(), Matrix() types and advanced functions like AngleBetweenVecs(v1,v2) and RotationMatrix(...)
  23. # import Mathutils 
  24.  
  25. # for functions like getWindowWidth(), getWindowHeight()
  26. # import Rasterizer
  27.  
  28. def main():
  29.     cont = GameLogic.getCurrentController()
  30.     
  31.     # The KX_GameObject that owns this controller.
  32.     own = cont.owner
  33.     
  34.     # for scripts that deal with spacial logic
  35.     own_pos = own.worldPosition
  36.     
  37.     
  38.     # Some example functions, remove to write your own script.
  39.     # check for a positive sensor, will run on any object without errors.
  40.     print 'Logic info for KX_GameObject', own.name
  41.     input = False
  42.     
  43.     for sens in cont.sensors:
  44.         # The sensor can be on another object, we may want to use it
  45.         own_sens = sens.owner
  46.         print '    sensor:', sens.name,
  47.         if sens.positive:
  48.             print '(true)'
  49.             input = True
  50.         else:
  51.             print '(false)'
  52.     
  53.     for actu in cont.actuators:
  54.         # The actuator can be on another object, we may want to use it
  55.         own_actu = actu.owner
  56.         print '    actuator:', actu.name
  57.         
  58.         # This runs the actuator or turns it off
  59.         # note that actuators will continue to run unless explicitly turned off.
  60.         if input:
  61.             cont.activate(actu)
  62.         else:
  63.             cont.deactivate(actu)
  64.     
  65.     # Its also good practice to get sensors and actuators by name
  66.     # rather then index so any changes to their order wont break the script.
  67.     
  68.     # sens_key = cont.sensors['key_sensor']
  69.     # actu_motion = cont.actuators['motion']
  70.     
  71.     
  72.     # Loop through all other objects in the scene
  73.     sce = GameLogic.getCurrentScene()
  74.     print 'Scene Objects:', sce.name
  75.     for ob in sce.objects:
  76.         print '   ', ob.name, ob.worldPosition
  77.     
  78.     
  79.     # Example where collision objects are checked for their properties
  80.     # adding to our objects "life" property
  81.     """
  82.     actu_collide = cont.sensors['collision_sens']
  83.     for ob in actu_collide.objectHitList:
  84.         # Check to see the object has this property
  85.         if ob.has_key('life'):
  86.             own['life'] += ob['life']
  87.             ob['life'] = 0
  88.     print own['life']
  89.     """
  90.  
  91. main()
  92. '''
  93.  
  94. new_text = bpy.data.texts.new('gamelogic_example.py')
  95. new_text.write(script_data)
  96. bpy.data.texts.active = new_text
  97. Window.RedrawAll()
  98.